import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


/*
 * In this class is programmed:
 * the connection to the database
 * the saving of the data 
 */
public class DataBaseSaver{
	private Connection con = null;
	
	public DataBaseSaver(){
		connect();
	}
	
	public void connect(){
	    try {
	      Class.forName("com.mysql.jdbc.Driver");
	      con = DriverManager.getConnection("jdbc:mysql:///unwdmi","root", "");
	    } catch(SQLException e){
	    	e.printStackTrace();
//	    } catch (InstantiationException e) {			
//			e.printStackTrace();
//		} catch (IllegalAccessException e) {		
//			e.printStackTrace();
		} catch (ClassNotFoundException e) {	
			e.printStackTrace();
		}	    

	}
	
	public void save(Data data){
		String query= "INSERT INTO weather_data VALUES ('0', ";
		query += data.getStn() + ", ";
		query+= "'" +data.getDate()+ "', ";
		query+= "'" +data.getTime() + "', ";
		query+= data.getTemp() + ", ";
		query+= data.getDewp() + ", ";
		query+= data.getStp() + ", ";
		query+= data.getSlp() + ", ";
		query+= data.getVisib() + ", ";
		query+= data.getWdsp() + ", ";
		query+= data.getPrcp() + ", ";
		query+= data.getSndp() + ", ";
		query+= data.getFrshtt() + ", ";
		query+= data.getCldc() + ", ";
		query+= data.getWnddir();		
		query += ")";		
		
		try {			
			Statement statement = con.createStatement();
			statement.execute(query);			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	

}